/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.gar.bc;

import edu.upn.sigemfi.gar.be.ItemPignoraticio;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Freddy
 */
public class ItemPignoraticioDelegate {

    private ItemPignoraticioFacadeLocal local;

    public ItemPignoraticioDelegate(){
        local = lookupItemPignoraticioFacade();
    }

    private ItemPignoraticioFacadeLocal lookupItemPignoraticioFacade() {
        try {
            Context c = new InitialContext();
            return (ItemPignoraticioFacadeLocal) c.lookup("java:comp/env/ItemPignoraticioFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void crear(ItemPignoraticio itemPignoraticio) throws Exception
    {
        try{
            local.create(itemPignoraticio);
        }
        catch(Exception ex){
            local=lookupItemPignoraticioFacade();
            throw new Exception("Crear Item Pignoraticio"+ex.getMessage());
        }
    }

    public void editar(ItemPignoraticio itemPignoraticio) throws Exception
    {
        try{
            local.edit(itemPignoraticio);
        }
        catch(Exception ex){
            local=lookupItemPignoraticioFacade();
            throw new Exception("Editar Item Pignoraticio"+ex.getMessage());
        }
    }

    public void remove(ItemPignoraticio itemPignoraticio) throws Exception
    {
        try{
            local.remove(itemPignoraticio);
        }
        catch(Exception ex){
            local=lookupItemPignoraticioFacade();
            throw new Exception("Remover Item Pignoraticio"+ex.getMessage());
        }
    }
}
